let app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    postId: 1,
    activeTab: 1,
    topTabList: [
      { id: 1, name: 'ھەممىسى' },
      { id: 2, name: 'ئوقىۋاتقان' },
      { id: 3, name: 'ئوقۇپ بولغان' },
      { id: 4, name: 'ئاڭلاۋاتقان' },
      { id: 5, name: 'ئاڭلاپ بولغان' },
    ],
    kitapCon: [],
    pageNo: 1,
    pageSize: 30,
  },

  // 获取预览
  getPreview () {
    let userInfo = wx.getStorageSync('userInfo');
    let user_id = userInfo.user.id;
    let data = { user_id: user_id, pageNo: this.data.pageNo, pageSize: this.data.pageSize }
    let that = this;
    wx.request({
      url: `${app.globalData.API_URL}/getPreview`,
      method: 'POST',
      data: data,
      header: {
        'content-type': 'application/json',
      },
      success(res) {
        if (res.statusCode) {
          that.setData({ kitapCon: res.data.data });
        }
      },
    });
  },

  // 点击 Tab
  onClickTab(item) {
    let tabId = item.currentTarget.dataset.item.id;
    switch (tabId) {
      case 1:
        this.setData({ kitapCon: [] })
        this.getPreview();
        break;
      case 2:
        this.setData({ kitapCon: [] })
        break;
      case 3:
        this.setData({ kitapCon: [] })
        break;
      case 4:
        this.getPreview();
        break;
      case 5:
        this.setData({ kitapCon: [] })
        break;
    
      default:
        break;
    }
    this.setData({ activeTab: tabId });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({ postId: options.listId });
    this.getPreview();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: 'قىيات ئاۋازلىق ئەسەر',
      path: '/pages/inUse/inUse',
      imageUrl: 'https://mmecoa.qpic.cn/sz_mmecoa_png/iauAIibMdU78thJHXKBcIfYLNA6zH3pbFllMLlSibhVriaGwtS0bM1tLLyz6OSlQ74icF6c4Yic4icLokYGvb2jXnY8bA/640?wx_fmt=png&amp;from=appmsg'
    };
  }
})